//
//  RdbUserDefaults.swift
//  rdb-led-banner
//  UserDefaults 的工具类
//  Created by radiobox3 on 2025/4/17.
//

import Foundation

class RdbUserDefaults: NSObject {
    
    
    static func update(value: Any, keyPath: RdbUserDefaults.key){
        UserDefaults.standard.setValue(value, forKeyPath: keyPath.rawValue)
        UserDefaults.standard.synchronize()
    }
    
    static func boolValue(for keyPath: RdbUserDefaults.key) -> Bool{
        return UserDefaults.standard.bool(forKey: keyPath.rawValue)
    }
    
    static func stringValue(for keyPath: RdbUserDefaults.key) -> String?{
        return UserDefaults.standard.string(forKey: keyPath.rawValue)
    }
    
    static func value(for keyPath: RdbUserDefaults.key) -> Any? {
        return UserDefaults.standard.object(forKey: keyPath.rawValue)
    }
    static func remove(for keyPath: RdbUserDefaults.key) {
        UserDefaults.standard.removeObject(forKey: keyPath.rawValue)
    }
    
}


extension RdbUserDefaults{
    public struct key {
        public var rawValue: String
        public init(_ rawValue: String){
            self.rawValue = rawValue
        }
    }
}

extension RdbUserDefaults.key {
    
    static let rdbFirstLaunch = RdbUserDefaults.key("firstLaunch")
    static let rdbSubscribeExpireDate = RdbUserDefaults.key("subscribeExpireDateKey")
    static let rdbTrialPeriod = RdbUserDefaults.key("trialPeriod")
    static let rdbPopRating = RdbUserDefaults.key("rdbPopRating")
    static let rdbThemeColor = RdbUserDefaults.key("rdbThemeColor")
    static let rdbSystemLanguage = RdbUserDefaults.key("rdbSystemLanguage")
}

